﻿Public Class RegexMatchesViewModel
    Inherits RegexViewModelBase
    Implements IEnumerable(Of RegexMatchViewModel)

#Region "Events"
    ' Insert Event Declarations Here
#End Region

#Region "Properties"
#Region "Constants"
    ' Insert Constant Declarations Here
#End Region

    Private _matches As MatchCollection
    Public Property Matches() As MatchCollection
        Get
            Return _matches
        End Get
        Private Set(ByVal value As MatchCollection)
            _matches = value
        End Set
    End Property

    Private _matchViewModels As IEnumerable(Of RegexMatchViewModel)
    Public Property MatchViewModels() As IEnumerable(Of RegexMatchViewModel)
        Get
            Return _matchViewModels
        End Get
        Private Set(ByVal value As IEnumerable(Of RegexMatchViewModel))
            _matchViewModels = value
        End Set
    End Property

    Public ReadOnly Property Count As Integer
        Get
            'Subtract 1 because the first item is always the original Match (which is not included in the collection)
            Return Me.Matches.Count - 1
        End Get
    End Property

    Public Overrides ReadOnly Property Index As Integer
        Get
            If Me.Matches.Count > 0 Then
                Return Me.Matches(0).Index
            Else
                Return 0
            End If
        End Get
    End Property

    Public Overrides ReadOnly Property Length As Integer
        Get
            If Me.Matches.Count > 0 Then
                Return Me.Matches(0).Length
            Else
                Return 0
            End If
        End Get
    End Property
#End Region

#Region "Constructors"
    Public Sub New(matches As MatchCollection, regex As Regex, viewNavigator As IViewNavigator)
        MyBase.New(regex, viewNavigator)

        Me.Matches = matches
        Me.MatchViewModels =
            From m In Me.Matches.Cast(Of Match)()
            Select New RegexMatchViewModel(m, regex, viewNavigator)
    End Sub
#End Region

#Region "Methods"
    Public Function GetEnumerator() As System.Collections.Generic.IEnumerator(Of RegexMatchViewModel) Implements System.Collections.Generic.IEnumerable(Of RegexMatchViewModel).GetEnumerator
        Return Me.MatchViewModels.GetEnumerator()
    End Function

    Private Function GetEnumerator1() As System.Collections.IEnumerator Implements System.Collections.IEnumerable.GetEnumerator
        Return GetEnumerator()
    End Function

#Region "Event Raiser Methods"
    ' Insert Method Declarations which Raise an Event Here
#End Region

#Region "Event Handlers"
    ' Insert Method Declarations which Handle an Event Here
#End Region
#End Region

End Class
